package com.zlq.cn.controller;


import com.zlq.cn.annotations.UnPrintResult;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.entity.ExamChapters;
import com.zlq.cn.entity.ZhTibetanDict;
import com.zlq.cn.service.un.ZhTibetanDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 中文藏文词典 前端控制器
 * </p>
 *
 * @author zhoucl
 * @since 2024-05-04
 */
@Api(tags = "公共-中文藏文词典")
@RestController
@RequestMapping("/api/common/zh/tibetan/dict")
public class ZhTibetanDictController {

    @Resource
    private ZhTibetanDictService zhTibetanDictService;

    @ApiOperation("所有数据")
    @GetMapping("/list")
    public SignApiResult<List<ZhTibetanDict>> list() {
        return SignApiResult.resultSuccess(zhTibetanDictService.list());
    }

    @ApiOperation("获取最新版本")
    @PostMapping("/last/version")
    @UnPrintResult
    public SignApiResult<String> lastVersion(@ApiIgnore @RequestBody ExamChapters examChapters) {
        return SignApiResult.resultSuccess(zhTibetanDictService.lambdaQuery()
                .select(ZhTibetanDict::getVersion)
                .last(" limit 1")
                .oneOpt().map(ZhTibetanDict::getVersion).orElse("1"));
    }
}

